/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bs.stock.rn;

import bs.facturacion.modelo.MovimientoFacturacion;
import bs.global.excepciones.ExcepcionGeneralSistema;
import bs.global.modelo.ComprobantePK;
import bs.stock.dao.ComprobanteInventarioDAO;
import bs.stock.modelo.ComprobanteStock;
import bs.stock.modelo.MovimientoStock;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

/**
 *
 * @author Claudio
 */
@Stateless
public class MovimientoStockRN {

    @EJB private ComprobanteInventarioDAO comprobanteDAO;

    @TransactionAttribute(TransactionAttributeType.REQUIRED)   
    public synchronized void guardar(MovimientoStock m) throws Exception {
        
    }
        
    public MovimientoStock generarComprobante(MovimientoFacturacion mf){
        
        MovimientoStock m = new MovimientoStock();        
        return m;        
    }
    
    
    public Integer getProximoNumeroComprobante(String modfor,String codfor){

        Integer proxNumero;
        Integer ultNumero = comprobanteDAO.getUltimoNumeroComprobante(modfor, codfor);

        if(ultNumero==null) proxNumero = 1;
        else proxNumero = ultNumero + 1;

        return proxNumero;

    }
    
    public ComprobanteStock getComprobante(ComprobantePK idPK) throws ExcepcionGeneralSistema{

        ComprobanteStock cs = comprobanteDAO.getComprobante(idPK);
        if(cs==null) throw new ExcepcionGeneralSistema("No se encontró comprobante de stock ("+idPK.getCodcom()+")");
        return cs;
    }

    public ComprobanteStock getComprobante(String modcom, String codcom) throws ExcepcionGeneralSistema{

        ComprobanteStock cs = comprobanteDAO.getComprobante(new ComprobantePK(modcom, codcom));
        if(cs==null) throw new ExcepcionGeneralSistema("No se encontró comprobante de stock ("+codcom+")");
        return cs;
    }

    public List<ComprobanteStock> getLista() {

        return comprobanteDAO.getLista();
    }






    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    
 
}
